﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using GestionLinqLibData;
using IRepositories;

namespace LinqRepositories
{
    public class LinqTypeExamRepository : ITypeExamRepository
    {
        GestionDataClassesDataContext db = new GestionDataClassesDataContext();

        #region ITypeExamRepository Membres

        public type_exam CreateExam(type_exam typeToCreate)
        {
            db.type_exam.InsertOnSubmit(typeToCreate);
            db.SubmitChanges();

            return typeToCreate;
        }

        public IEnumerable<type_exam> ListTypes()
        {
            return db.type_exam.ToList();
        }

        public type_exam GetType(int id_type)
        {
            return db.type_exam.Where(t => t.id_exam == id_type).First();

        }

        public type_exam EditType(type_exam typeToEdit)
        {
            var originalType = GetType(typeToEdit.id_exam);
            originalType.nom_exam = typeToEdit.nom_exam;
            db.SubmitChanges();

            return typeToEdit;
        }

        public void DeleteType(type_exam typeToDelete)
        {
            db.type_exam.DeleteOnSubmit(GetType(typeToDelete.id_exam));
            db.SubmitChanges();
        }

        #endregion
    }
}
